package com.yonyou.pmclouds.basecom.shiro.realm;

import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class PMFormAuthenticationFilter extends FormAuthenticationFilter {

    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
        HttpServletRequest req = (HttpServletRequest) request;
        this.setSuccessUrl(req.getRequestURI());
        return executeLogin(request, response);
    }

    protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
        UsernamePasswordToken token = new UsernamePasswordToken(RuntimeEnvironment.getLoginUserId(), "defaultpassword");
        return token;
    }

    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject,
                                     ServletRequest request, ServletResponse response) {
        return true;
    }
}
